import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

class DioDemoBase extends StatefulWidget {
  const DioDemoBase({Key? key}) : super(key: key);

  @override
  _DioDemoBaseState createState() => _DioDemoBaseState();
}

class _DioDemoBaseState extends State<DioDemoBase> {
  List _list = [];

  @override
  initState() {
    super.initState();

    _getData();
  }

  _getData() async {
    var response = await Dio().get("https://jdmall.itying.com/api/pcate");

    setState(() {
      _list = response.data["result"];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Dio Demo Base"),
        centerTitle: true,
      ),
      body: _list.isNotEmpty
          ? ListView(
              children: _list.map((value) {
                return Column(children: [
                  ListTile(
                    title: Text("${value['title']}"),
                  ),
                  const Divider()
                ]);
              }).toList(),
            )
          : const Center(
              child: CircularProgressIndicator(),
            ),
    );
  }
}
